/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InternalFrameClientes.java
 *
 * Created on 17/01/2011, 18:27:01
 */
package gui.frames.internos.relatorios;

import controle.gui.frames.internos.relatorios.ControleLogUsuarios;
import controle.gui.superclasses.InternalFrame;
import controle.gui.utils.ApagaElementosDaInterface;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import controle.utils.ReportUtils;
import gui.componentes.JTextFieldCodigo;
import gui.componentes.MascarasJTextField;
import persistencia.session.ConnectionFactory;

/**
 *
 * @author Maycon
 */
public class IFLogUsuarios extends InternalFrame {

    private ControleLogUsuarios controle = new ControleLogUsuarios(this);

    /**
     * Creates new form InternalFrameClientes
     */
    public IFLogUsuarios() {
        initComponents();
        setVisible(true);
        inicializa();
    }

    /**
     * Inicializa as opções personalizadas para esta GUI*
     */
    @Override
    public void inicializa() {
        controle.inicializa();
    }

    /**
     * Limpa e reinicializa elementos desta GUI
     */
    @Override
    protected void limparGUI() {
        controle.limparGUI();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        groupPeriodo = new javax.swing.ButtonGroup();
        groupEntidade = new javax.swing.ButtonGroup();
        groupPagamento = new javax.swing.ButtonGroup();
        groupConclusao = new javax.swing.ButtonGroup();
        panelBotoes = new javax.swing.JPanel();
        buttonCancelar = new javax.swing.JButton();
        buttonLimpar = new javax.swing.JButton();
        buttonImprimir = new javax.swing.JButton();
        panelDefinicoes = new javax.swing.JPanel();
        labelEntidade = new javax.swing.JLabel();
        comboUsuarios = new javax.swing.JComboBox();
        textCodigoAgente = new JTextFieldCodigo(3, true);
        panelPeriodo = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        radioTodoPeriodo = new javax.swing.JRadioButton();
        radioDurantePeriodo = new javax.swing.JRadioButton();
        textPeriodoInicial = new javax.swing.JFormattedTextField(new MascarasJTextField().inserirMascara("##/##/####"));
        ((JFormattedTextField)textPeriodoInicial).setFocusLostBehavior(JFormattedTextField.COMMIT);
        jLabel2 = new javax.swing.JLabel();
        textPeriodoFinal = new javax.swing.JFormattedTextField(new MascarasJTextField().inserirMascara("##/##/####"));
        ((JFormattedTextField)textPeriodoFinal).setFocusLostBehavior(JFormattedTextField.COMMIT);

        setClosable(true);
        setIconifiable(true);
        setTitle("Relatório de Log de Usuários");
        setToolTipText("");

        panelBotoes.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Opções", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        buttonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/Cancelar.png"))); // NOI18N
        buttonCancelar.setText("Cancelar");
        buttonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonCancelarActionPerformed(evt);
            }
        });

        buttonLimpar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/Novo.png"))); // NOI18N
        buttonLimpar.setText("Limpar");
        buttonLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonLimparActionPerformed(evt);
            }
        });

        buttonImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/Imprimir.png"))); // NOI18N
        buttonImprimir.setText("Imprimir");
        buttonImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonImprimirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelBotoesLayout = new javax.swing.GroupLayout(panelBotoes);
        panelBotoes.setLayout(panelBotoesLayout);
        panelBotoesLayout.setHorizontalGroup(
            panelBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotoesLayout.createSequentialGroup()
                .addComponent(buttonImprimir)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonLimpar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonCancelar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        panelBotoesLayout.setVerticalGroup(
            panelBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotoesLayout.createSequentialGroup()
                .addGroup(panelBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonImprimir)
                    .addComponent(buttonLimpar)
                    .addComponent(buttonCancelar))
                .addGap(0, 0, Short.MAX_VALUE))
        );

        panelDefinicoes.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Usuários", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        labelEntidade.setText("Agente:>");

        comboUsuarios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboUsuariosActionPerformed(evt);
            }
        });

        textCodigoAgente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textCodigoAgenteActionPerformed(evt);
            }
        });
        textCodigoAgente.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                textCodigoAgenteFocusLost(evt);
            }
        });

        javax.swing.GroupLayout panelDefinicoesLayout = new javax.swing.GroupLayout(panelDefinicoes);
        panelDefinicoes.setLayout(panelDefinicoesLayout);
        panelDefinicoesLayout.setHorizontalGroup(
            panelDefinicoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDefinicoesLayout.createSequentialGroup()
                .addComponent(labelEntidade)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(textCodigoAgente, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(comboUsuarios, javax.swing.GroupLayout.PREFERRED_SIZE, 389, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        panelDefinicoesLayout.setVerticalGroup(
            panelDefinicoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDefinicoesLayout.createSequentialGroup()
                .addGroup(panelDefinicoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelEntidade)
                    .addComponent(textCodigoAgente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comboUsuarios, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelPeriodo.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Período", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jLabel1.setText("De:");

        groupPeriodo.add(radioTodoPeriodo);
        radioTodoPeriodo.setSelected(true);
        radioTodoPeriodo.setText("Todas as ocorrências");
        radioTodoPeriodo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioTodoPeriodoActionPerformed(evt);
            }
        });

        groupPeriodo.add(radioDurantePeriodo);
        radioDurantePeriodo.setText("Entre:");
        radioDurantePeriodo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioDurantePeriodoActionPerformed(evt);
            }
        });

        ((JFormattedTextField)textPeriodoInicial).setHorizontalAlignment(textPeriodoInicial.LEFT);
        textPeriodoInicial.setEnabled(false);

        jLabel2.setText("Até:");

        ((JFormattedTextField)textPeriodoFinal).setHorizontalAlignment(textPeriodoFinal.LEFT);
        textPeriodoFinal.setEnabled(false);

        javax.swing.GroupLayout panelPeriodoLayout = new javax.swing.GroupLayout(panelPeriodo);
        panelPeriodo.setLayout(panelPeriodoLayout);
        panelPeriodoLayout.setHorizontalGroup(
            panelPeriodoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPeriodoLayout.createSequentialGroup()
                .addGroup(panelPeriodoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(radioTodoPeriodo)
                    .addGroup(panelPeriodoLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textPeriodoInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textPeriodoFinal, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(radioDurantePeriodo))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        panelPeriodoLayout.setVerticalGroup(
            panelPeriodoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPeriodoLayout.createSequentialGroup()
                .addComponent(radioTodoPeriodo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(radioDurantePeriodo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(panelPeriodoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(textPeriodoInicial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(textPeriodoFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelDefinicoes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(panelPeriodo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(panelBotoes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(panelDefinicoes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(panelPeriodo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(panelBotoes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Filtra as opções escolhida e executa o relatório
     *
     * @param evt
     */
    private void buttonImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonImprimirActionPerformed
        controle.imprimir();
}//GEN-LAST:event_buttonImprimirActionPerformed

    public void radioTodoPeriodoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioTodoPeriodoActionPerformed
        controle.eventoRadioTodoPeriodoAction();
    }//GEN-LAST:event_radioTodoPeriodoActionPerformed

    public void radioDurantePeriodoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioDurantePeriodoActionPerformed
        controle.eventoRadioDurantePeriodo();
    }//GEN-LAST:event_radioDurantePeriodoActionPerformed

    private void textCodigoAgenteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textCodigoAgenteActionPerformed
        controle.eventoTextCodigoAgentes(getTextCodigoAgente(), comboUsuarios, true);
    }//GEN-LAST:event_textCodigoAgenteActionPerformed

    private void comboUsuariosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboUsuariosActionPerformed
        controle.eventoComboAgentes(comboUsuarios, textCodigoAgente);
    }//GEN-LAST:event_comboUsuariosActionPerformed

    private void textCodigoAgenteFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_textCodigoAgenteFocusLost
        controle.eventoTextCodigoAgentes(textCodigoAgente, comboUsuarios, true);
    }//GEN-LAST:event_textCodigoAgenteFocusLost

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonCancelar;
    private javax.swing.JButton buttonImprimir;
    private javax.swing.JButton buttonLimpar;
    private javax.swing.JComboBox comboUsuarios;
    private javax.swing.ButtonGroup groupConclusao;
    private javax.swing.ButtonGroup groupEntidade;
    private javax.swing.ButtonGroup groupPagamento;
    private javax.swing.ButtonGroup groupPeriodo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel labelEntidade;
    private javax.swing.JPanel panelBotoes;
    private javax.swing.JPanel panelDefinicoes;
    private javax.swing.JPanel panelPeriodo;
    private javax.swing.JRadioButton radioDurantePeriodo;
    private javax.swing.JRadioButton radioTodoPeriodo;
    private javax.swing.JTextField textCodigoAgente;
    private javax.swing.JTextField textPeriodoFinal;
    private javax.swing.JTextField textPeriodoInicial;
    // End of variables declaration//GEN-END:variables
    
    public javax.swing.JButton getButtonCancelar() {
        return buttonCancelar;
    }

    public javax.swing.JButton getButtonImprimir() {
        return buttonImprimir;
    }

    public javax.swing.JButton getButtonLimpar() {
        return buttonLimpar;
    }

    public javax.swing.JComboBox getComboUsuarios() {
        return comboUsuarios;
    }

    public javax.swing.ButtonGroup getGroupConclusao() {
        return groupConclusao;
    }

    public javax.swing.ButtonGroup getGroupEntidade() {
        return groupEntidade;
    }

    public javax.swing.ButtonGroup getGroupPagamento() {
        return groupPagamento;
    }

    public javax.swing.ButtonGroup getGroupPeriodo() {
        return groupPeriodo;
    }

    public javax.swing.JLabel getjLabel1() {
        return jLabel1;
    }

    public javax.swing.JLabel getjLabel2() {
        return jLabel2;
    }

    public javax.swing.JLabel getLabelEntidade() {
        return labelEntidade;
    }

    public javax.swing.JPanel getPanelBotoes() {
        return panelBotoes;
    }

    public javax.swing.JPanel getPanelDefinicoes() {
        return panelDefinicoes;
    }

    public javax.swing.JPanel getPanelPeriodo() {
        return panelPeriodo;
    }

    public javax.swing.JRadioButton getRadioDurantePeriodo() {
        return radioDurantePeriodo;
    }

    public javax.swing.JRadioButton getRadioTodoPeriodo() {
        return radioTodoPeriodo;
    }

    public javax.swing.JTextField getTextCodigoAgente() {
        return textCodigoAgente;
    }

    public javax.swing.JTextField getTextPeriodoFinal() {
        return textPeriodoFinal;
    }

    public javax.swing.JTextField getTextPeriodoInicial() {
        return textPeriodoInicial;
    }
}
